package lab1.io;

import config.Config;
import operations.FileOperations;

import java.io.*;

public class FileIO {

    public static final int BUFFER_SIZE = 2048;
    public static final int TESTS_NUMBER = 1000;
    public static final String RES_FILE = "FileIO.bin";


    /**
     * Copy file on the local computer.
     * This method isn't fast.
     * Method calculate time of copying using IO.
     *
     * @param args
     */
    public static void main(String[] args) {
        for (int i = 0; i < TESTS_NUMBER; i++) {

            try {
                File f = new File(RES_FILE);
                FileOperations.getEmptyFile(f);

                try (BufferedReader br = new BufferedReader(new FileReader(Config.INITIAL_FILE), BUFFER_SIZE);
                     BufferedWriter bw = new BufferedWriter(new FileWriter(f), BUFFER_SIZE)) {
                    String sCurrentLine;

                    long start = System.currentTimeMillis();
                    while ((sCurrentLine = br.readLine()) != null) {
                        bw.write(sCurrentLine);
                        bw.flush();
                    }
                    long end = System.currentTimeMillis();
                    System.out.println(end - start);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } catch (Exception e) {
            }
        }


    }

}
